package leetcode_周赛._2021._202112._12;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/12/12 10:52
 */
public class _5953 {

    public long subArrayRanges(int[] nums) {
        int ans = 0;
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            int min = nums[i], max = nums[i];
            for (int j = i; j < len; j++) {
                min = Math.min(min, nums[j]);
                max = Math.max(max, nums[j]);
                ans += max - min;
            }
        }
        return ans;
    }

}
